﻿using Inaction.Service.Client;
using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace Client
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += Application_ThreadException;
            var f = new LoginForm();
            if (!(f.ShowDialog() == DialogResult.Yes
                && Inaction.Security.Principal.Instance != null
                && Inaction.Security.Principal.Instance.Identity.IsAuthenticated))
            {
                System.Environment.Exit(System.Environment.ExitCode);
            }
            var formStr = Inaction.AppConfig.Instance.StartUpView.Split(';');
            Form form = Inaction.Util.TypeHelper.LoadTypeInstance<Form>(formStr[0], formStr[1]);
            if (form == null)
            {
                MessageBox.Show("主窗口未能加载，请检查");
            }
            else
            {               
                Application.Run(form);
            }
        }

        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            Inaction.Util.Loger.WriteLog(e.Exception);
            MessageBox.Show(e.Exception.GetMessage(true));
        }
    }
}
